package string_question.leecode.test14;

/**
 * 方法二： 按位进行遍历(自己写)
 * @author code_yc
 * @version 1.0
 * @date 2020/7/5 10:18
 */
public class Solution2 {

    public String longestCommonPrefix(String[] strs) {
        if (strs == null || strs.length == 0) return "";
        StringBuilder res = new StringBuilder();
        int index = 0;
        char cur;
        while (true) {
            if (index == strs[0].length()) {
                break;
            }
            cur = strs[0].charAt(index);
            for (int i = 1; i < strs.length; i++) {
                if (index == strs[i].length() || cur != strs[i].charAt(index)) {
                    return res.toString();
                }
            }
            res.append(cur);
            index++;
        }
        return res.toString();
    }
}
